<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Cache-Control"  content="no-transform">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>用户登录</title>
    <link href="/statics/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/statics/view/css/all.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        body{
            background: #ffffff;
        }
    </style>
</head>
<body>
[#include "/common/header.ftl" /]

<div class="container">
    <h2>用户登录</h2>
    <form id="loginForm">
        <div class="form-group">
            <label for="username">用户名</label>
            <input  type="text" class="form-control" name="username" id="username" placeholder="您的手机号码">
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" name="password" id="password" placeholder="您在本保险平台的密码">
        </div>
        <button type="submit" class="btn btn-default">登录</button>
    </form>
</div>
<div class="container si-nav-tools">
    <div class="row">
        <div class="col-sm-3 col-xs-3 div-right">
            <a href="/" class="act">首页</a>
        </div>
    </div>
</div>
<script type="text/javascript" src="/statics/jquery/jquery.js"></script>
<script type="text/javascript" src="/statics/view/js/common.js"></script>
<script type="text/javascript" src="/statics/view/js/jquery.validate.js"></script>
<script type="text/javascript" src="/statics/view/js/jsbn.js"></script>
<script type="text/javascript" src="/statics/view/js/prng4.js"></script>
<script type="text/javascript" src="/statics/view/js/rng.js"></script>
<script type="text/javascript" src="/statics/view/js/rsa.js"></script>
<script type="text/javascript" src="/statics/view/js/base64.js"></script>


<script type="text/javascript">
    $().ready(function() {

        var $loginForm = $("#loginForm");
        var $username = $("#username");
        var $password = $("#password");

        var $submit = $(":submit");

        // 记住用户名
        if (getCookie("memberUsername") != null) {
            $username.val(getCookie("memberUsername"));
            $password.focus();
        } else {
            $username.focus();
        }

        // 表单验证、记住用户名
        $loginForm.validate({
            rules: {
                username: "required",
                password: "required",
            submitHandler: function(form) {
                $.ajax({
                    url: "${base}/common/public_key.do",
                    type: "GET",
                    dataType: "json",
                    cache: false,
                    success: function(data) {
                        var rsaKey = new RSAKey();
                        rsaKey.setPublic(b64tohex(data.modulus), b64tohex(data.exponent));
                        var enPassword = hex2b64(rsaKey.encrypt($password.val()));
                        $.ajax({
                            url: $loginForm.attr("action"),
                            type: "POST",
                            data: {
                                username: $username.val(),
                                enPassword: enPassword
                            },
                            dataType: "json",
                            cache: false,
                            success: function(message) {
                                addCookie("memberUsername", $username.val(), {expires: 7 * 24 * 60 * 60});
                                $submit.prop("disabled", false);
                                if (message.type == "success") {
                                [#if redirectUrl??]
                                    location.href = "${redirectUrl}";
                                [#else]
                                    location.href = "${base}/";
                                [/#if]
                                } else {
                                    $.message(message);
                                }
                            }
                        });
                    }
                });
            }
        });

    });
</script>
<script type="application/javascript">
    $(function(){
        $('#myTab a').click(function (e) {
            e.preventDefault()
            $(this).tab('show')
        })
    });
</script>
</body>
</html>